//package com.kuang.interceptor;
//
//import com.kuang.pojo.UserIp;
//import com.kuang.service.UserIpService;
//import com.kuang.util.Ip2Region;
//import com.kuang.util.IpUtile;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Date;
//
//public class SiteIndexInterceptor implements HandlerInterceptor {
//    @Autowired
//    private UserIpService userIpService;
//
//    public SiteIndexInterceptor(UserIpService userIpService) {
//        this.userIpService = userIpService;
//    }
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String requestURI = request.getRequestURI();
//        StringBuffer requestURL = request.getRequestURL();
//        String url = requestURL.toString();
//        int count = 0;
//        if (!url.contains(".png") && !url.contains(".jpg") && !url.contains("jpeg") && !url.contains("/plugins") && !url.contains("/js") && !url.contains(".css") && !url.contains(".js")) {
////            System.out.println("url = " + url);
//            String remoteAddr = IpUtile.getRemoteAddr(request);
//            String ipRegion = Ip2Region.getIpRegion(remoteAddr);
////            count++;
//            UserIp userIp = new UserIp();
//            userIp.setUpdateTime(new Date());
//            userIp.setCreateTime(new Date());
////            userIp.setUrl(url2);
//            userIp.setIp(remoteAddr);
//            userIp.setAddress(ipRegion);
//            userIp.setUrl(url);
//            if (!url.contains("/admin")){
//                int i = userIpService.insertUserIp(userIp);
//                System.out.println("userIp = " + userIp);
//
//
//            }
//
////            System.out.println("url2 = " + url2);
//
////            System.out.println("remoteAddr = " + remoteAddr);
////            System.out.println("ipRegion = " + ipRegion);
////            System.out.println("userIpService = " + userIpService);
////            System.out.println("i = " + i);
//
//        }
//
//
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        StringBuffer requestURL = request.getRequestURL();
////        System.out.println("requestURI 拦截器里的 = " + requestURI);
////        System.out.println("requestURL = " + requestURL);
////        System.out.println("userIpService = " + userIpService);
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//
//    }
//}
